package com.fita.entity.wallet;

import com.demo2do.core.utils.Alias;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @description:
 * @author: 11200
 * @date: 2019/7/1
 */
@Alias("transactionType")
public enum TransactionType {

    RECHARGE("充值"),

    WITHDRAW("提现"),

    AGENT_DISTRIBUTION_REWARD("代理分销奖励"),

    RENT_CAR("租车消费");

    private String description;

    /**
     *
     * @param description
     */
    TransactionType(String description) {
        this.description = description;
    }

    /**
     * 是否是收入
     * @return
     */
    public boolean isIncome(){
        return this.equals(RECHARGE) || this.equals(AGENT_DISTRIBUTION_REWARD);
    }

    /**
     * 是否是支出
     * @return
     */
    public boolean isExpenses(){
        return this.equals(WITHDRAW) || this.equals(RENT_CAR);
    }

    /**
     *
     * @return
     */
    public List<TransactionType> getIncomeTypes(){

        List<TransactionType> transactionTypes = Arrays.stream(TransactionType.values()).filter(transactionType -> transactionType.isIncome()).collect(Collectors.toList());
        return transactionTypes;
    }

    /**
     *
     * @return
     */
    public List<TransactionType> getExpansesTypes(){
        List<TransactionType> transactionTypes = Arrays.stream(TransactionType.values()).filter(transactionType -> transactionType.isExpenses()).collect(Collectors.toList());
        return transactionTypes;
    }

    /**
     * 收支类型描述
     * @return
     */
    public String getTypeDescription(){
        return this.isIncome() ? "收入" : this.isExpenses() ? "支出" :  "未知类型";
    }

    public String getDescription() {
        return description;
    }

    public boolean isRecharge(){
        return this.equals(RECHARGE);
    }

    public boolean isWithdraw(){
        return this.equals(WITHDRAW);
    }

    public boolean isAgentDistributionReward(){
        return this.equals(AGENT_DISTRIBUTION_REWARD);
    }

    public boolean isRentCar(){return this.equals(RENT_CAR);}
}
